#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

using namespace std;

int _main()
{
	//Create window for application
	sf::RenderWindow App(sf::VideoMode::GetMode(0), "Dyna Bomber", sf::Style::Fullscreen);
	
	int start[2] = {200, 200};
	int end[2] = {600, 600};
	int step = 0;
	int q, r;
	q = r = 0;
	int x = 120;
	sf::Randomizer::GetSeed();

	while(App.IsOpened())
	{
		sf::Event Event;
		while(App.GetEvent(Event))
		{
			//If close button or escape is pressed
			if(Event.Type == sf::Event::Closed ||
			 ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)))
			{
				App.Close(); 
				break;
			}			
		}

		App.Clear();
		++step;
		if (step>=x)
		{
			r = sf::Randomizer::Random(0, 4); //1,2,3,4 == top, right, down, left
			q = sf::Randomizer::Random(0, 4);
			step = 0;
		}
		switch (r)
		{
		case 0 : break;
		case 1: if (start[1] < App.GetWidth() ) ++start[1]; else { r = 3; step = x/2; }  break;
		case 2: if (start[0] < App.GetHeight() ) ++start[0]; else { r = 4; step = x/2; } break;
		case 3: if (start[1] > 0 ) --start[1]; else { r = 1; step = x/2; } break;
		case 4: if (start[0] > 0 ) --start[0]; else { r = 2; step = x/2; } break;
		}
		
		switch (q)
		{
		case 0 : break;
		case 1: if (end[1] < App.GetWidth()) ++end[1]; else { q = 3; step = x/2;} break;
		case 2: if (end[0] < App.GetHeight()) ++end[0]; else { q = 4; step = x/2; } break;
		case 3: if (end[1] > 0 ) --end[1]; else { q = 1; step = x/2; } break;
		case 4: if (end[0] > 0 ) --end[0]; else { q = 2; step = x/2; } break;
		}
		
		App.Draw(sf::Shape::Line(start[0], start[1], end[0], end[1], 3, sf::Color(step, 0, 255-step)));

		App.Display();
	}

    return 0;
}
